/**
 * kl yy-ds @2021
 */
package com.cxps.server.thread.controller;

import com.cxps.server.thread.service.ThreadProductService;
import com.cxps.server.thread.service.ThreadService2;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * TODO(类描述)
 *
 * @author YouCai.Liu
 * @since 2021/11/30
 * ...
 */
@Slf4j
@Api(tags = "多线程批量处理")
@RestController
@RequestMapping("/thread")
public class ThreadProductController {

    @Autowired
    private ThreadProductService threadProductService;


    /**
     * 单线程批量插入数据
     *
     * @return
     */
    @GetMapping("/oneThread")
    public String oneThread() {
        threadProductService.oneThread();
        return "SUCCESS";
    }

    /**
     * 多线程批量插入数据
     *
     * @return
     */
    @GetMapping("/moreThread")
    public String moreThread() {
//        threadProductService.moreThread();

        System.out.println();
        log.info("======================我是分界线=======================");
        System.out.println();

        threadProductService.moreThread2();
        return "SUCCESS";
    }

    @GetMapping("/getFlag")
    public String getFlag() {
        ThreadService2 threadService2 = new ThreadService2();
        System.out.println(threadService2.isFlag()); // false

        threadService2.setFlag(true);

        System.out.println(threadService2.isFlag()); // true

        ThreadService2 threadService21 = new ThreadService2();
        System.out.println(threadService21.isFlag()); // false

        Map<String,String> map = new HashMap<>();

        return "SUCCESS";

    }

}
